package com.sinog.front.controller.biz;

import com.sinog.core.util.DateUtil;
import com.sinog.core.util.JsonUtil;
import com.sinog.core.utilbean.Constants;
import com.sinog.core.utilbean.Result;
import com.sinog.front.feign.biz.AddStatusStatisticsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @desc 数据统计分析 - 添加状态统计 - AddStatusStatisticsController
 * @author ybl
 * @date 2022/8/10
 */
@RestController
public class AddStatusStatisticsController {

    @Resource
    private AddStatusStatisticsService addStatusStatisticsService;

    /**
     * 系统管理 - 信息查看 - 数据状态查看分析 - 拿到所有的单位
     * @param begin 开始时间
     * @param end 结束时间
     * @param pstate 新增状态
     * @return Result
     */
    @GetMapping("/azbj/sjtjfx/xzzttj/getUnit")
    public Result getUnit(
            @RequestParam(required = false, defaultValue = "-1") String begin,
            @RequestParam(required = false, defaultValue = "-1") String end,
            @RequestParam(required = false) String pstate,
            @RequestParam(required = false) String province,
            @RequestParam(required = false) String[] pstateType,
            @RequestParam(required = false) String unitId) {
        if(Constants.NumberStr.NUM_STR_FU_ONE.equals(begin)) {
            begin = DateUtil.getSpecifiedTime(-7);
            end = DateUtil.getSpecifiedTime(-1);
        }
        Map<String,Object> map = new HashMap<>(16);
        map.put("beginTime",begin);
        map.put("endTime",end);
        map.put("pstate",pstate);
        map.put("province",province);
        map.put("unitId",unitId);
        map.put("pstateType",pstateType);
        return addStatusStatisticsService.getUnit(JsonUtil.toText(map));
    }

    /**
     * 系统管理 - 信息查看 - 数据状态查看分析 - 拿到对应数据
     * @param begin 开始时间
     * @param end 结束时间
     * @param pstate 新增状态
     * @return Result
     */
    @GetMapping("/azbj/sjtjfx/xzzttj/getStatusStatisticsData")
    public Result getStatusStatisticsData(
            @RequestParam(required = false, defaultValue = "-1") String begin,
            @RequestParam(required = false, defaultValue = "-1") String end,
            @RequestParam(required = false) String pstate,
            @RequestParam(required = false) String province,
            @RequestParam(required = false) String id,
            @RequestParam(required = false, defaultValue = "1") int dateType) {
        if(Constants.NumberStr.NUM_STR_FU_ONE.equals(begin)) {
            begin = DateUtil.getSpecifiedTime(-7);
            end = DateUtil.getSpecifiedTime(-1);
        }
        Map<String,Object> map = new HashMap<>(16);
        map.put("beginTime",begin);
        map.put("endTime",end);
        map.put("pstate",pstate);
        map.put("province",province);
        map.put("id",id);
        map.put("dateType",dateType);
        return addStatusStatisticsService.addStatusStatisticsData(JsonUtil.toText(map));
    }

    /**
     * 系统管理 - 信息查看 - 数据状态查看分析 - 拿到对应数据
     * @param pageIndex 分页起始索引
     * @param pageSize 分页条数
     * @param begin 开始时间
     * @param end 结束时间
     * @param pstateType 状态数组
     * @return String
     */
    @GetMapping("/azbj/sjtjfx/xzzttj/getResultData")
    public String getResultData(Integer pageIndex,Integer pageSize,
                                @RequestParam(required = false) String begin,
                                @RequestParam(required = false) String end,
                                @RequestParam(required = false) String[] pstateType,
                                @RequestParam(required = false) String unitId,
                                @RequestParam(required = false) String province,
                                @RequestParam(required = false) String sortField,
                                @RequestParam(required = false) String sortOrder) {
        Map<String,Object> map = new HashMap<>(16);
        map.put("beginTime",begin);
        map.put("endTime",end);
        map.put("pstateType",pstateType);
        map.put("province",province);
        map.put("unitId",unitId);
        map.put("sortField",sortField);
        map.put("sortOrder",sortOrder);
        return addStatusStatisticsService.getResultData(pageIndex,pageSize,JsonUtil.toText(map));
    }

    /**
     * 系统管理 - 信息查看 - 数据状态查看分析 - 状态列表仅有
     * @return List<Map<String,Object>>
     */
    @RequestMapping("/azbj/sjtjfx/xzzttj/getPstateList")
    public List<Map<String,Object>> getPstateList() {
        return addStatusStatisticsService.getPstateList();
    }

    /**
     * 系统管理 - 信息查看 - 数据状态查看分析 - 省份列表
     * @return List<Map<String,Object>>
     */
    @RequestMapping("/azbj/sjtjfx/xzzttj/getProvince")
    public List<Map<String,String>> getProvince() {
        return addStatusStatisticsService.getProvince();
    }

    /**
     * 系统管理 - 信息查看 - 数据状态查看分析 - 状态列表
     * @return List<Map<String,Object>>
     */
    @RequestMapping("/azbj/sjtjfx/xzzttj/getSort")
    public List<Map<String,Object>> getSort() {
        return addStatusStatisticsService.getSort();
    }

    /**
     * 系统管理 - 信息查看 - 数据状态查看分析 - 状态列表
     * @return List<Map<String,Object>>
     */
    @RequestMapping("/azbj/sjtjfx/xzzttj/getSortDetails")
    public List<Map<String,Object>> getSortDetails(@RequestParam(required = false) String id) {
        return addStatusStatisticsService.getSortDetails(id);
    }

    /**
     * 系统管理 - 信息查看 - 数据状态查看分析 - 当前省份
     * @return String
     */
    @RequestMapping("/azbj/sjtjfx/xzzttj/getCurrentProvince")
    public String getCurrentProvince() {
        return addStatusStatisticsService.getCurrentProvince();
    }

    /**
     * 系统管理 - 信息查看 - 数据状态查看分析 - 拿到总计数据
     * @return List<Map<String,Object>>
     */
    @RequestMapping("/azbj/sjtjfx/xzzttj/getTotalData")
    public List<Map<String,Object>> getTotalData() {
        return addStatusStatisticsService.getTotalData();
    }
}